/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sorting;

/**
 *
 * @author Student
 */
public class Sorting {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        //insertion sort
        int arr[] = new int[5000000];

        arr = initArray();

        print(arr);
        for (int i = 1; i < arr.length; i++) {
            int item = arr[i];
            int iHole = i;
            while (iHole > 0 && arr[iHole - 1] > item) {
                arr[iHole] = arr[iHole - 1];
                iHole = iHole - 1;
                
            }
            arr[iHole] = item;
        }
        System.out.println("");
        System.out.println("");
        print(arr);
    }

    private static void print(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
            
        }
        System.out.println("");


    }

    private static int[] initArray() {
        int arr[] = new int[500000];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 100);
        }
        return arr;
    }
}
